Using Variables
To use the value of a variable in a script, include the variable in a command or expression. For example, the first statement in the following example creates a variable, calledmyName
, whose value is the string"Mitch"
. The second statement uses the variablemyName
in place of a string as thedefault answer
parameter of the Display Dialog command.
set myName to "Mitch"display dialog "What is your name?" default answer myNameIf you assign a new value to a variable, it replaces the old value. The following script shows what happens when you assign a new value. It uses the Display Dialog command to display the values. Try running this script:
set myName to "Mitch"display dialog ("The value of myName is now " & myName) ¬ buttons "Sure Is" default button 1 set myName to "Warren"display dialog ("The value of myName is now " & myName) ¬ buttons "You Betcha" default button 1The first Display Dialog command displays the value stored by the first assignment statement (the string"Mitch"
). The next Display Dialog
command displays the value after the second assignment statement (the
string"Warren"
).